package com.mmall.concurrency.sync;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Slf4j
public class SysExam1 {

    public void test1(int j){
        synchronized (this){
            for (int i=0;i<10;i++){
                log.info("test1:{}-{}",j,i);
            }
        }
    }

    public synchronized void test2(int j){
        for (int i=0;i<10;i++){
            log.info("test2:{}-{}",j,i);
        }
    }



    public static void main(String[] args) {
        SysExam1 sysExam1=new SysExam1();
        SysExam1 sysExam2=new SysExam1();
        ExecutorService executorService=Executors.newCachedThreadPool();
        executorService.execute(()->{
            sysExam1.test2(1);
        });
        executorService.execute(()->{
            sysExam2.test2(2);
        });
    }

}
